package com.yj.timecapsule.common.response;
import com.yj.timecapsule.common.enums.ErrorCode;
import lombok.Data;
import lombok.NoArgsConstructor;

/**
 * @author Sean
 * responseData
 */
@Data
@NoArgsConstructor
public class CommonResponseType<T> {
    private Integer code;
    /**
     * 业务上的成功 或者 失败
     */
    private boolean success = true;
    /**
     * 返回信息
     */
    private String message;
    /**
     * 返回泛型数据 自定义类型
     */
    private T content;

    public static<T> CommonResponseType<T> success(){
        CommonResponseType<T> commonResponseType = new CommonResponseType<>();
        commonResponseType.success = true;
        commonResponseType.message = ErrorCode.SUCCESS.getMsg();
        commonResponseType.setCode(ErrorCode.SUCCESS.getCode());
        return commonResponseType;

    }
    public static<T> CommonResponseType<T> success(T content){
        CommonResponseType<T> commonResponseType = success();
        commonResponseType.content = content;
        return commonResponseType;
    }
    public static<T> CommonResponseType<T> error(Integer code,String message){
        CommonResponseType<T> commonResponseType = new CommonResponseType<>();
        commonResponseType.success = false;
        commonResponseType.message = message;
        commonResponseType.setCode(code);
        return commonResponseType;
    }
}
